package com.du.stutestsys.serverImpl.TeacherManageImpl;

import com.du.stutestsys.dao.ExercisesMapper;
import com.du.stutestsys.entity.Exercises;
import com.du.stutestsys.service.TeacherManage.ExercisesService;
import com.du.stutestsys.util.DuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ExercisesServiceimpl implements ExercisesService {
    @Autowired
    ExercisesMapper exercisesMapper;

    @Override
    @Transactional
    public boolean addExercises(Exercises exercises,String answers[]) {
        //这个应该是前端做的
//        if (exercises.getType().equals("1") ||exercises.getType().equals("2")){
//            if (answers.length < 2){      //如果是单选或者多选，则答案至少是2个
//               return false;
//            }
//        }
        boolean ok1 =  exercisesMapper.insert(exercises)>0;
        boolean ok2 =  exercisesMapper.addAnswers(exercises,answers)>0;
        return DuUtil.isAdds(new Boolean[]{ok1, ok2});
    }
}
